#ifndef DIRECTSAMPLING
#define DIRECTSAMPLING 
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <gdal/cpl_conv.h>
#include <gdal/ogrsf_frmts.h>
#include "KDindex.h"

typedef struct {
    int dvminx,dvminy,dvminz;
    int dvmaxx,dvmaxy,dvmaxz;
} dv_bnd;

using namespace std;

void load_ti_3D(float ** ti, char *file, int *length, int *width, int *height);

float direct_sampling_cont(float * ti, int width, int height, float *dv, int NR_try, float tolerance,int dvminx,int dvmaxx,int dvminy, int dvmaxy);
void Simulation_cont(Index <L2<float> > *R, float *ti, int NR_neighbor,int NR_try, float tolerance, vector<coord> &sample, vector<int> &ids, float *values, int N_sample, int tilength, int tiwidth, int tiheight, int unitsize, int start_id, int level, int xsize, int ysize, int zsize);
float direct_sampling(float * ti, int width, int height, float *dv, int NR_try, float tolerance,int dvminx,int dvmaxx,int dvminy, int dvmaxy);

/**
 * @brief Perform simulation on the random points on the level
 *
 * @param R  The index for neighboring pixels
 * @param ti The training image
 * @param NR_neighbor These three parameters are for directsampling
 * @param NR_try
 * @param tolerance
 * @param sample The random point samples
 * @param ids The id of all samples. This is going to be filled in this function.
 * @param values The target image.
 * @param N_sample The number of samples.
 * @param tilength The training image length.
 * @param tiwidth The training image width.
 * @param tiheight The training image height.
 * @param unitsize The average cell size of the imagined grid.
 * @param start_id The position of the first sample to be simulated in the parameter sample
 * @param level The level of details.
 * @param xsize, ysize, zsize. The simulation grid size
 */
void Simulation(Index <L2<float> > *R, float *ti, int NR_neighbor,int NR_try, float tolerance, vector<coord> &sample, vector<int> &ids, int *values, int N_sample, int tilength, int tiwidth, int tiheight, int unitsize, int start_id, int level, int xsize, int ysize, int zsize);
#endif /* ifndef DIRECTSAMPLING */
